Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Circular reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Circular_reference"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Circular_reference rootpage-Circular_reference skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Circular reference</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">This article is about a series of references where the last object references the first. For Multiple sources for single-source data, see <a href="Circular_reporting" title="Circular reporting">Circular reporting</a>.</div>

<p>A <b>circular reference</b> (or <b>reference cycle</b><sup id="cite_ref-rustrefcycle_1-0" class="reference"><a href="#cite_note-rustrefcycle-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>) is a series of <a href="Reference" title="Reference">references</a> where the last object references the first, resulting in a closed loop.
</p>

<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Simple_example">Simple example</h2></div>
<p>A newcomer asks a local where the town library is. "Just in front of the post office," says the local. The newcomer nods, and follows up: "But where is the post office?"
</p><p>"Why, that's simple," replies the local. "It's just behind the library!"
</p>
<div class="mw-heading mw-heading2"><h2 id="In_language">In language</h2></div>
<p>A circular reference is not to be confused with the <a href="Logical_fallacy" class="mw-redirect" title="Logical fallacy">logical fallacy</a> of a <a href="Circular_argument" class="mw-redirect" title="Circular argument">circular argument</a>. Although a circular reference will often be unhelpful and reveal no information, such as two entries in a book index referring to each other, it is not necessarily so that a circular reference is of no use. Dictionaries, for instance, must always ultimately be a circular reference since all words in a dictionary are defined in terms of other words, but a dictionary nevertheless remains a useful reference. Sentences containing circular references can still be meaningful:
</p>
<dl><dd><i>Her brother gave her a kitten; his sister thanked him for it.</i></dd></dl>
<p>is circular, but not without meaning. Indeed, it can be argued that self-reference is a necessary consequence of Aristotle's <a href="Law_of_non-contradiction" class="mw-redirect" title="Law of non-contradiction">law of non-contradiction</a>, a fundamental philosophical <a href="Axiom" title="Axiom">axiom</a>. In this view, without self-reference, <a href="Logic" title="Logic">logic</a> and <a href="Mathematics" title="Mathematics">mathematics</a> become impossible, or at least, lack usefulness.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Fiengo_3-0" class="reference"><a href="#cite_note-Fiengo-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="In_computer_programming">In computer programming</h2></div>
<div role="note" class="hatnote navigation-not-searchable">For circular references between objects or resources, see <a href="Reference_counting" title="Reference counting">Reference counting</a>.</div>
<p>Circular references can appear in <a href="Computer_programming" title="Computer programming">computer programming</a> when one piece of code requires the result from another, but that code needs the result from the first. For example, the two functions, posn and plus1 in the following Python program comprise a circular reference:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="k">def</span><span class="w"> </span><span class="nf">posn</span><span class="p">(</span><span class="n">k</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="n">plus1</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="n">k</span>

<span class="k">def</span><span class="w"> </span><span class="nf">plus1</span><span class="p">(</span><span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="k">return</span> <span class="n">posn</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
<p>Circular references like the above example may return valid results if they have a terminating condition. If there is no terminating condition, a circular reference leads to a condition known as <a href="Livelock" class="mw-redirect" title="Livelock">livelock</a> or <a href="Infinite_loop" title="Infinite loop">infinite loop</a>, meaning it theoretically could run forever.
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="k">def</span><span class="w"> </span><span class="nf">posn</span><span class="p">(</span><span class="n">k</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="k">return</span> <span class="n">plus1</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>

<span class="k">def</span><span class="w"> </span><span class="nf">plus1</span><span class="p">(</span><span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
<span class="k">return</span> <span class="n">posn</span><span class="p">(</span><span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>
<p>In ISO Standard, SQL circular integrity constraints are implicitly supported within a single table. Between multiple tables circular constraints (e.g. foreign keys) are permitted by defining the constraints as deferrable (See <a rel="nofollow" class="external text" href="http://www.postgresql.org/docs/current/static/sql-createtable.html">CREATE TABLE</a> for PostgreSQL and <a rel="nofollow" class="external text" href="http://docs.oracle.com/cd/B19306_01/server.102/b14200/clauses002.htm#i1015767">DEFERRABLE Constraint Examples</a> for Oracle). In that case the constraint is checked at the end of the transaction not at the time the DML statement is executed. To update a circular reference, two statements can be issued in a single transaction that will satisfy both references once the transaction is committed.
</p><p>Circular references can also happen between instances of data of a mutable type, such as in this Python script:
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="n">mydict</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">"this"</span><span class="p">:</span> <span class="s2">"that"</span><span class="p">,</span>
<span class="s2">"these"</span><span class="p">:</span> <span class="s2">"those"</span>
<span class="p">}</span>
<span class="n">mydict</span><span class="p">[</span><span class="s2">"myself"</span><span class="p">]</span> <span class="o">=</span> <span class="n">mydict</span>
<span class="nb">print</span><span class="p">(</span><span class="n">mydict</span><span class="p">)</span>
</pre></div>
<p>The <code class="mw-highlight mw-highlight-lang-python mw-content-ltr" style="" dir="ltr"><span class="nb">print</span><span class="p">(</span><span class="n">mydict</span><span class="p">)</span></code> function will output <code class="mw-highlight mw-highlight-lang-python mw-content-ltr" style="" dir="ltr"><span class="p">{</span><span class="s1">'this'</span><span class="p">:</span> <span class="s1">'that'</span><span class="p">,</span> <span class="s1">'these'</span><span class="p">:</span> <span class="s1">'those'</span><span class="p">,</span> <span class="s1">'myself'</span><span class="p">:</span> <span class="p">{</span><span class="o">...</span><span class="p">}}</span></code>, where <code class="mw-highlight mw-highlight-lang-python mw-content-ltr" style="" dir="ltr"><span class="p">{</span><span class="o">...</span><span class="p">}</span></code> indicates a circular reference, in this case, to the <code class="mw-highlight mw-highlight-lang-python mw-content-ltr" style="" dir="ltr"><span class="n">mydict</span></code> dictionary.
</p>
<div class="mw-heading mw-heading2"><h2 id="In_spreadsheets">In spreadsheets</h2></div>
<p>Circular references also occur in <a href="Spreadsheet" title="Spreadsheet">spreadsheets</a> when two cells require each other's result. For example, if the value in Cell A1 is to be obtained by adding 5 to the value in Cell B1, and the value in Cell B1 is to be obtained by adding 3 to the value in Cell A1, no values can be computed. (Even if the specifications are A1:=B1+5 and B1:=A1-5, there is still a circular reference. It does not help that, for instance, A1=3 and B1=-2 would satisfy both formulae, as there are infinitely many other possible values of A1 and B1 that can satisfy both instances.)
</p><p>Circular reference in worksheets can be a very useful technique for solving implicit equations such as the <a href="Colebrook_equation" class="mw-redirect" title="Colebrook equation">Colebrook equation</a> and many others, which might otherwise require tedious <a href="Newton-Raphson" class="mw-redirect" title="Newton-Raphson">Newton-Raphson</a> algorithms in VBA or use of macros.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p><p>A distinction should be made with processes containing a circular reference between those that are incomputable and those that are an iterative calculation with a final output. The latter may fail in spreadsheets not equipped to handle them but are nevertheless still logically valid.<sup id="cite_ref-Fiengo_3-1" class="reference"><a href="#cite_note-Fiengo-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Causality" title="Causality">Causality</a>&nbsp;– How one process influences another</li>
<li><a href="Circular_reporting" title="Circular reporting">Circular reporting</a>&nbsp;– Multiple sources for single-source data</li>
<li><a href="Halting_problem" title="Halting problem">Halting problem</a>&nbsp;– Problem in computer science</li>
<li><a href="MS_Fnd_in_a_Lbry" title="MS Fnd in a Lbry">MS Fnd in a Lbry</a>&nbsp;– Short story by Hal Draper</li>
<li><a href="Nested_function" title="Nested function">Nested function</a>&nbsp;– A named function defined within a function</li>
<li><a href="Quine_(computing)" title="Quine (computing)">Quine (computing)</a>&nbsp;– Self-replicating program</li>
<li><a href="Regress_argument" class="mw-redirect" title="Regress argument">Regress argument</a>&nbsp;– Philosophical problem<span style="display:none" class="category-annotation-with-redirected-description">Pages displaying short descriptions of redirect targets</span></li>
<li><a href="Self-reference" title="Self-reference">Self-reference</a>&nbsp;– Sentence, idea or formula that refers to itself</li>
<li><a href="There's_a_Hole_in_My_Bucket" title="There's a Hole in My Bucket">There's a Hole in My Bucket</a>&nbsp;– Classic, humorous children's song</li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist reflist-columns references-column-width reflist-columns-2">
<ol class="references">
<li id="cite_note-rustrefcycle-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-rustrefcycle_1-0">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="rustrefcycle" class="citation web cs1">Klabnik, Steve; Nichols, Carol. <a rel="nofollow" class="external text" href="https://doc.rust-lang.org/book/ch15-06-reference-cycles.html">"Reference Cycles Can Leak Memory"</a>. <i>The Rust Programming Language</i>. Rust Team<span class="reference-accessdate">. Retrieved <span class="nowrap">8 November</span> 2023</span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><a href="Terry_A._Osborn" title="Terry A. Osborn">Terry A. Osborn</a>, <a rel="nofollow" class="external text" href="https://books.google.com/books?id=fvJTwwCSy8UC&amp;dq=%22circular+reference%22+-excel+-computer+-programming&amp;pg=PA32"><i>The future of foreign language education in the United States</i></a>, pp.31-33, Greenwood Publishing Group, 2002 <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-89789-719-6</bdi>.</span>
</li>
<li id="cite_note-Fiengo-3"><span class="mw-cite-backlink">^ <a href="#cite_ref-Fiengo_3-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Fiengo_3-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text">Robert Fiengo, Robert May, <a rel="nofollow" class="external text" href="https://books.google.com/books?id=V77kaAVpU0UC&amp;dq=%22circular+reference%22+-excel+-computer+-programming&amp;pg=PA60"><i>Indices and identity</i></a>, pp.59-62, MIT Press, 1994 <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-262-56076-3</bdi>.</span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20090817224237/http://www.frpdesigns.com/iteration.htm">"Solve Implicit Equations Inside Your Worksheet By Anilkumar M, Dr Sreenivasan E and Dr Raghunathan K"</a>. Archived from <a rel="nofollow" class="external text" href="http://www.frpdesigns.com/iteration.htm">the original</a> on 2009-08-17<span class="reference-accessdate">. Retrieved <span class="nowrap">2009-06-25</span></span>.</cite>.</span>
</li>
</ol></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-05-20" href="https://en.wikipedia.org/wiki/?title=Circular_reference&amp;oldid=1291257008">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>